package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Log;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.service.LogService;
import com.atguigu.jxc.service.OverFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author dyqstart
 * @create 2021-09-04-20:23
 * @since 1.0.0
 */
@RestController
@RequestMapping("/overflowListGoods")
public class OverFlowController {

    @Autowired
    OverFlowService overFlowService;

    @Autowired
    LogService logService;

    @PostMapping("/save")
    public ServiceVO saveOverFlow(OverflowList overflowList, String overflowListGoodsStr){

        overFlowService.saveOverFlow(overflowList,overflowListGoodsStr);
        Log log = new Log(Log.INSERT_ACTION,"添加报溢单");
        logService.save(log);
        return new ServiceVO(100,"请求成功",null);
    }

    @PostMapping("/list")
    public Map<String,Object> getOverflowListGoods(String sTime,String eTime){

        Map<String,Object> map = overFlowService.getOverflowListGoods(sTime,eTime);
        Log log = new Log(Log.SELECT_ACTION,"查询指定区间报溢单列表");
        logService.save(log);
        return map;
    }

    @PostMapping("/goodsList")
    public Map<String,Object> getOverflowListGoodsByOverflowListId(Integer overflowListId){
        Map<String,Object> map = overFlowService.getOverflowListGoodsByOverflowListId(overflowListId);
        Log log = new Log(Log.SELECT_ACTION,"查询报溢商品列表");
        logService.save(log);
        return map;
    }
}
